package com.meirengu.webview.service.impl;

import com.meirengu.service.impl.BaseServiceImpl;
import com.meirengu.webview.dao.KwWxInteractiveDao;
import com.meirengu.webview.model.KwWxInteractive;
import com.meirengu.webview.service.KwWxInteractiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * KwWxInteractive服务实现层
 *
 * @author Liu
 * @create Tue Dec 04 14:01:19 CST 2018
 */
@Service
public class KwWxInteractiveServiceImpl extends BaseServiceImpl<KwWxInteractive> implements KwWxInteractiveService {
    @Autowired
    private KwWxInteractiveDao kwWxInteractiveDao;

    @Override
    public List<KwWxInteractive> getModel(Map map) {
        return kwWxInteractiveDao.getModel(map);
    }

    @Override
    public void insert(Map map) {
        String openId = map.get("FromUserName").toString();
        String toUserName = map.get("ToUserName").toString();
        Map<String, Object> paramsMap = new HashMap<>();
        paramsMap.put("fromUserName", openId);
        paramsMap.put("toUserName", toUserName);
        int count = kwWxInteractiveDao.getCount(paramsMap);
        if (count < 1) {
            KwWxInteractive kwWxInteractive = new KwWxInteractive();
            kwWxInteractive.setFromUserName(openId);
            kwWxInteractive.setToUserName(toUserName);
            kwWxInteractive.setInteractiveEvent(0);
            kwWxInteractiveDao.insert(kwWxInteractive);
        }
    }
}
